package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.TicketRecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.TicketRecordService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 ticketRecordController
@RequestMapping("/ticketRecordController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /ticketRecordController
public class TicketRecordController {
	@Resource
    TicketRecordService ticketRecordService;
	@RequestMapping("/getAllTicketRecord")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<TicketRecord> getAllTicketRecord() throws Exception{
    	System.out.println("查询消费券记录");
    	return ticketRecordService.getAllTicketRecords();
    }
	@RequestMapping("/addTicketRecord")
	@ResponseBody
	public DTO<TicketRecord> addTicketRecord(@RequestBody TicketRecord ticketRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加消费券记录成功");
		return ticketRecordService.addTicketRecord(ticketRecord);
	}

	@RequestMapping("/deleteTicketRecordByArcno/{arcno}")
	@ResponseBody
    public DTO<TicketRecord> deleteTicketRecordByArcno(@RequestBody@PathVariable("arcno") String arcno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(arcno+"删除消费券记录成功");
    	return ticketRecordService.deleteTicketRecordByArcno(arcno);
    }



	@RequestMapping("/getTicketRecordByArcno/{arcno}")
	@ResponseBody
	public DTO<TicketRecord> getTicketRecordByArcno(@PathVariable("arcno") String arcno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(arcno+"根据主键查询消费券记录成功");
		return ticketRecordService.getTicketRecordByArcno(arcno);
	}

	@RequestMapping("/updateTicketRecordByArcno")
	@ResponseBody
	public DTO<TicketRecord> updateTicketRecordByArcno(@RequestBody TicketRecord ticketRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改消费券记录成功");
		System.out.println(ticketRecord);
		return ticketRecordService.updateTicketRecordByArcno(ticketRecord);
	}

	@RequestMapping("/getTicketRecordByPage")
	@ResponseBody
	public DTO<TicketRecord> getTicketRecordByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询消费券记录成功");
		return ticketRecordService.getTicketRecordByPage(pageInfo);
	}

}
